package data;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.stream.Collectors;

public class FileINOUT {
    public static void FileSaveToJs(String content,String filePath) {

        try (BufferedWriter writer = new BufferedWriter(new FileWriter(filePath))) {
            writer.write(content); // 将字符串写入文件
            System.out.println("String saved to file successfully.");
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("An error occurred while saving the string to file.");
        }
    }
    public static String readFactsToString(String path){
        String content = "";
        try {
            List<String> lines = Files.readAllLines(Paths.get(path));
            content = lines.stream().collect(Collectors.joining(System.lineSeparator()));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return content;
    }
}
